//
//  NSPhotoNavView.m
//  Meboo
//
//  Created by kyo on 2024/4/18.
//

#import "NSPhotoNavView.h"
#import "NSVipPopView.h"
@interface NSPhotoNavView ()
@property (nonatomic, strong) UIButton *leftBtn;

@property (nonatomic, strong) UIButton *photoBtn;

@property (nonatomic, strong) UIButton *privateBtn;
@property (nonatomic, strong) NSVipPopView *vipPopView;


@end

@implementation NSPhotoNavView

#pragma mark - Life Cycle
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

#pragma mark - Action
- (void)leftAction {
    [self.currentViewController.navigationController popViewControllerAnimated:YES];
}

- (void)photoAction {
    self.photoBtn.titleLabel.font = MBHelBoldFontSizeScale(16);
    self.privateBtn.titleLabel.font = MBHelFontSizeScale(16);
    if (self.photoBlock) {
        self.photoBlock(NO);
    }
}

- (void)privateAction {
    self.privateBtn.titleLabel.font = MBHelBoldFontSizeScale(16);
    self.photoBtn.titleLabel.font = MBHelFontSizeScale(16);
    NSString *ioStr = @"";
    if ([MBUserAccount defaultAccount].isVip) {
        ioStr = @"Chat_PrivateAlbum";
    } else {
//        [self.currentViewController.view addSubview:self.vipPopView];
//        self.vipPopView.index = 5;
//        self.vipPopView.hidden = NO;
        ioStr = @"Chat_PrivateAlbum_Sub";
    }
    if (self.photoBlock) {
        self.photoBlock(YES);
    }
    
    /**
     埋点
     私聊页点击私密相册成为会员拉起会员订阅 Chat_PrivateAlbum_Sub
     点击私密相册 Chat_PrivateAlbum
     */
    [[NSIOApiManager sharedManager] setIOWithEventName:ioStr];
}

#pragma mark - UI
- (void)setupUI {
    
    self.backgroundColor = UIColor.clearColor;
    
    [self addSubview:self.leftBtn];
    [self.leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(MBWidthScale(16));
        make.right.mas_equalTo(MBWidthScale(-16));
        make.bottom.mas_equalTo(MBHeightScale(-5));
        make.width.height.mas_equalTo(MBHeightScale(18));
    }];
    
    [self addSubview:self.photoBtn];
    [self.photoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.leftBtn);
        make.left.mas_equalTo(MBWidthScale(20));
    }];
    
    [self addSubview:self.privateBtn];
    [self.privateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.leftBtn);
        make.left.equalTo(self.photoBtn.mas_right).offset(MBWidthScale(30));
    }];
    
    //pop
    [self vipPopView];
}

#pragma mark - Setter && Getter
- (UIButton *)leftBtn {
    if (!_leftBtn) {
        _leftBtn = [[UIButton alloc] init];
        [_leftBtn setYXEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
        [_leftBtn setImage:ImageWithName(@"wlm_vip_pop_close") forState:0];
        [_leftBtn addTarget:self action:@selector(leftAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _leftBtn;
}

- (UIButton *)photoBtn {
    if (!_photoBtn) {
        _photoBtn = [[UIButton alloc] init];
        [_photoBtn setYXEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
        [_photoBtn setTitle:@"My Photo" forState:0];
        _photoBtn.titleLabel.font = MBHelBoldFontSizeScale(16);
        [_photoBtn setTitleColor:HEXS(@"333333") forState:0];
        [_photoBtn addTarget:self action:@selector(photoAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _photoBtn;
}

- (UIButton *)privateBtn {
    if (!_privateBtn) {
        _privateBtn = [[UIButton alloc] init];
        [_privateBtn setYXEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
        [_privateBtn setTitle:@"Private Album" forState:0];
        _privateBtn.titleLabel.font = MBHelFontSizeScale(16);
        [_privateBtn setTitleColor:HEXS(@"333333") forState:0];
        [_privateBtn addTarget:self action:@selector(privateAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _privateBtn;
}

- (NSVipPopView *)vipPopView {
    if (!_vipPopView) {
        _vipPopView = [[NSVipPopView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        _vipPopView.payBlock = ^{
            /**
             埋点
             私聊页点击私密相册成为会员拉起会员订阅支付成功 Chat_PrivateAlbum_Subsuccess
             */
            [[NSIOApiManager sharedManager] setIOWithEventName:@"Chat_PrivateAlbum_Subsuccess"];
        };
    }
    return _vipPopView;
}
@end
